package com.infore.statisticsAndAlarm.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.infore.statisticsAndAlarm.select.util.PageObject;
import com.infore.statisticsAndAlarm.service.IKnowledegBaseService;
import com.infore.statisticsAndAlarm.util.ResultEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "知识库文件管理接口", tags = { "知识库文件管理接口" })
@RestController
@RequestMapping("/knowledegBase")
public class KnowledegBaseController {

	@Autowired
	private IKnowledegBaseService iKnowledegBaseService;

	@ApiOperation(value = "展示知识库文件")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "knowledgeType", value = "知识库类型(1-6),空-查询全部", paramType = "query", required = false, dataType = "String"),
			@ApiImplicitParam(name = "fileType", value = "文件类型", paramType = "query", required = false, dataType = "String"),
			@ApiImplicitParam(name = "keyWorld", value = "关键词搜索", paramType = "query", required = false, dataType = "String") })
	@GetMapping(value = "/query")
	public ResultEntity query(String knowledgeType, String fileType, String keyWorld, PageObject pageObject) {
		return iKnowledegBaseService.query(knowledgeType, fileType, keyWorld, pageObject);
	}

	@ApiOperation(value = "新增知识库文件")
	@ResponseBody
	@ApiImplicitParams({
			@ApiImplicitParam(name = "knowledgeType", value = "知识库类型(1-6)", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "fileType", value = "文件类型", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "fileDescribe", value = "文件简述", paramType = "query", required = true, dataType = "String"),
			@ApiImplicitParam(name = "fileName", value = "文件名称", paramType = "query", required = true, dataType = "String")})
	@PostMapping(value = "/add")
	public ResultEntity add(@RequestPart(value = "file", required = true) MultipartFile file, String knowledgeType,
			String fileType, String fileDescribe,String fileName) {
		return iKnowledegBaseService.add(file, knowledgeType, fileType, fileDescribe,fileName);
	}

	@ApiOperation(value = "删除知识库文件")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "ids", value = "删除文件id", paramType = "query", required = true, dataType = "String") })
	@DeleteMapping(value = "/delete")
	public ResultEntity delete(String ids) {
		return iKnowledegBaseService.delete(ids);
	}

	@ApiOperation(value = "知识库文件下载")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "文件id", paramType = "query", required = true, dataType = "String") })
	@GetMapping(value = "/download")
	public ResultEntity download(HttpServletResponse response, String id) {
		return iKnowledegBaseService.download(response, id);
	}
}
